# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_luaversions="5.1 5.2 5.3 5.4"
pkgname=lua-mqtt-publish
pkgver=0.5
pkgrel=0
pkgdesc="Lua module for simple MQTT connect, publish and disconnect"
url="https://github.com/ncopa/lua-mqtt-publish"
arch="all"
license="MIT"
makedepends="lua-mosquitto" # so build order can be calculated
options="!check"

for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-mqtt-publish:_split"
done

source="lua-mqtt-publish-$pkgver.tar.gz::https://github.com/ncopa/lua-mqtt-publish/archive/v$pkgver.tar.gz
	"

package() {
	for i in $_luaversions; do
		install -Dm644 "$builddir"/mqtt/publish.lua \
			"$pkgdir"/usr/share/lua/$i/mqtt/publish.lua
	done
}

_split() {
	local d= _ver=${subpkgname#lua}; _ver=${_ver%%-*}
	msg "_ver=$_ver"
	pkgdesc="$pkgdesc for Lua $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends="lua$_ver-mosquitto"
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}

sha512sums="
89a2796d97b3d4ff210ec86f958fdef7459db7829ef99bb85a7055aa632197922a3a1a9b0b9e33ab973a00e053557463a7468af51702086024516496d090ace4  lua-mqtt-publish-0.5.tar.gz
"
